from abc import ABC
from datetime import datetime

from ctaf_facade.enumerations.service_rsp_code_enum import ResponseCodeEnum, get_rsp_code_enum_by_value


class BaseServiceResp(ABC):
    def __init__(self, ctaf_service_name: str =None, ctaf_trace_id: str =None, rsp_code: ResponseCodeEnum =None):
        self.__ctaf_service_name: str = ctaf_service_name
        self.__ctaf_trace_id: str = ctaf_trace_id
        self.__response_timestamp: datetime = datetime.now()
        if rsp_code:
            self.__response_code: str = rsp_code.value

    def get_called_service_name(self) -> str:
        return self.__ctaf_service_name

    def get_ctaf_trace_id(self) -> str:
        return self.__ctaf_trace_id

    def set_called_service_name(self, ctaf_service_name: str) :
        self.__ctaf_service_name = ctaf_service_name

    def set_ctaf_trace_id(self, ctaf_trace_id: str) :
        self.__ctaf_trace_id = ctaf_trace_id

    def get_response_timestamp(self) -> datetime:
        return self.__response_timestamp

    def get_response_code_as_enum(self) -> ResponseCodeEnum:
        return get_rsp_code_enum_by_value(self.__response_code)

    def set_response_code(self, rsp_code: ResponseCodeEnum):
        self.__response_code = rsp_code.value

    def get_response_code_as_str(self) -> str:
        return self.__response_code

    def is_successful_call(self) -> bool:
        if self.__response_code == ResponseCodeEnum.SUCCESS_EXECUTE.value:
            return True
        else:
            return False